<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>读取本地文件</title>
</head>

<body>
    <button id="btn">展示index.js内容</button>
    <div id="package-json-area">
    </div>
</body>
<script>
const fs = require("fs");
const path = require("path");
let btn = document.getElementById("btn");
console.log(btn);
btn.addEventListener('click', function(e) {
    fs.readFile(path.join(__dirname, "index.js"), "utf-8", function(err, data) {
        if (err) {
            console.log(err);
        } else {
            console.log(data);
            document.getElementById("package-json-area").innerHTML = data;
        }
    })
})
</script>

</html>